<?php 

function loaduser(){
	
	if(! isset($_SESSION['user_id']) )my_direct("login.php?pr=".$_SERVER['REQUEST_URI']);
	$user = my_get_data_by_id( 'user'	,	'user_id' 	, $_SESSION['user_id']); 
	return $user;
}


function is_admin(){
	$user = loaduser();
	if($user['level_id'] < 3){
		return true;
	}
	return false;
	
}

function is_super(){
	$user = loaduser();
	if($user['level_id'] == 1){
		return true;
	}
	return false;
}

function admin_link( $enable , $disabled = '&nbsp;'){
 
	if(is_admin())
		return $enable;
	else
		return $disabled;
}

function fatal_error_page( $msg  , $page = "index.php"){
 
	$error = array($msg);
	$content = message_multi_error($error);
	generate_my_web( $content  ,"FATAL ERROR" , $page);
	exit;

}

function setting_menu($com){
	
}

function session_check(){ 
	$session = my_get_data_by_id( 'session_control','user_id' , $_SESSION['user_id']);
	if(session_id() <> $session['session_id'] ){
		//echo 'Session expired &nbsp; &nbsp; &nbsp;<a href="login.php">Login</a> kembali';exit;
		my_direct('login.php?logout='.session_id());
	}

	if( 1 * 60 <= ( microtime()-strtotime($session['datetime_update'])) ){
		echo 'Time Out &nbsp; &nbsp; &nbsp;<a href="login.php">Login</a> kembali';exit;
		//my_direct('login.php?logout='.session_id());
	}
}

 function kalkulasi_proses(){
	$query = "SELECT value FROM opsi_seting WHERE name='kalkulasi'";
	$res =my_query($query);
	while($row = my_fetch_array($res)){
		if((int)$row['value'] > 0){
			echo'<html><meta http-equiv="refresh" content="10;"/><body>Server sedang kalkulasi<br/>Halaman ini akan terbuka kembali setelah proses berakhir<br/><a href="login.php?logout='.session_id().'">Logout</a></body></html>';
			exit;
		}
	}
 }